package com.itbaizhan.consumer;

import com.itbaizhan.pojo.LivegoodsBuyMessage;
import com.itbaizhan.service.BuyactionConsumerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.function.Consumer;

/**
 * @author spf
 * @date 2024/3/8
 * @time 10:12
 */

@Component
@Slf4j
public class BuyactionConsumer {

    @Autowired
    private BuyactionConsumerService buyactionConsumerService;

    @Bean
    public Consumer<LivegoodsBuyMessage> livegoodsMessage(){
        return message -> {
            System.out.println(message);
            String itemId = message.getItemId();
            String user = message.getUsername();
            boolean result = buyactionConsumerService.buyaction(itemId, user);

            log.info("消息消费结果...." + result);
        };
    }

}
